package com.ccl.utils;

import com.vdurmont.emoji.EmojiParser;
import com.ccl.entity.Article;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Commons {
    //把Date格式化成 yyyy-mm-dd
    public static String dateFormat(Date created){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(created);
        return format;
    }

    //设置文章详情页的跳转路径
    public static String permalink(Integer articleId){
        return "/articleDetail/"+articleId;
    }

    //截取文章摘要
    public static String intro(Article article,Integer length){
        //获取文章内容
        String content = article.getContent();
        if(content.length()>length){
            //如果文章够长,截取
            //截取指定长度
            String substring = content.substring(0, length);
            return substring+"......";
        }
        //如果文章不够长,直接显示
        return content;
    }

    //文章缩略图
    public static String show_thumb(Article article){
        //获取缩略图
        String thumbnail = article.getThumbnail();
        if(thumbnail!=null && thumbnail!=""){
            return thumbnail;
        }else{
            //随机显示一张图片
            return "/user/img/rand/"+article.getId()+".png";
        }
    }

    //文章内容
    public static String article(String content){
        return content;
    }

    //回到前台首页
    public static String site_url(){
        return "/";
    }

    public static String site_url(String url){
        return url;
    }

}
